import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

import routes from './routes';

const router = new VueRouter({
	mode: "hash",           // hash 加#       history   /
	base: process.env.BASE_URL,
	routes
});

//  路由守卫配置
router.beforeEach((to, from, next) => {
	const token = localStorage.getItem('store') ? JSON.parse(localStorage.getItem('store')).token : '';
	let {path, name} = to || {};
	if (token || to.name == 'login') {
		next()
	} else {
		next('/login')
	}
});
router.afterEach((vm) => {
});

export default router;
